/**
 * 
 */
package com.android.weibogo;

import android.content.Context;
import android.graphics.Color;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

/**
 * @author xiang.jianhua
 *
 */
public class WeiboCommentListAdapter extends WeiboAdapter {
	
	private Context context;

	public WeiboCommentListAdapter(Context ctx, ListView mView) {
		super(mView);
		this.context = ctx;
	}

	/* (non-Javadoc)
	 * @see com.android.weibogo.WeiboAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (position < getWbList().size()) {
			convertView = LayoutInflater.from(context).inflate(
					R.layout.comment_list, null);
			TextView wbText = (TextView) convertView.findViewById(R.id.wbtext);
			TextView wbTime = (TextView) convertView.findViewById(R.id.wbtime);
			TextView wbUser = (TextView) convertView.findViewById(R.id.wbuser);
			WeiboInfo wbInfo = getWbList().get(position);
			if (wbInfo != null) {
				convertView.setTag(wbInfo.getId());
				wbUser.setText(wbInfo.getUserName());
				wbTime.setText(wbInfo.getTime());
				wbText.setText(wbInfo.getText(), TextView.BufferType.SPANNABLE);
				WeibogoUtility.textHighlight(wbText, '#', '#');
				WeibogoUtility.textHighlight(wbText, '@', ':');
				WeibogoUtility.textHighlight(wbText, '@', ' ');
				WeibogoUtility.textHighlight2(wbText, "http://", " ");
			}
		} else if(position != 0){
			// show next page item
			LinearLayout layout = new LinearLayout(context);
			TextView textView = new TextView(context);
			LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
					LinearLayout.LayoutParams.WRAP_CONTENT);
			p.setMargins(0, 5, 0, 5);
			layout.addView(textView, p);
			textView.setGravity(Gravity.CENTER);
			textView.setTextSize(18);
			textView.setTextColor(Color.BLUE);
			textView.setText(context.getString(R.string.list_next_page));
			convertView = layout;
		}
		return convertView;
	}

}
